﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using ShredTheLog.Api.DataContracts;
using System.ComponentModel.Composition;
using ShredTheLog.Api;
using System.Diagnostics.Contracts;

namespace ShredTheLog.Converters
{
    [ValueConversion(typeof(Gender), typeof(string))]
    public sealed class GenderConverter : ConverterBase, IValueConverter
    {
        [Import]
        private IShredServices ShredServices { get; set; }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var v = (Gender)value;
            Type enumType = v.GetType();
            string key = String.Format("s_{0}_{1}", enumType.Name, Enum.GetName(enumType, v));
            Contract.Assume(!String.IsNullOrWhiteSpace(key));
            return ShredServices.GetLocalizedString(key);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        public static readonly GenderConverter Default = new GenderConverter();
    }
}
